package cn.imnaer.service.rpc.userinfo.dao;

import cn.imnaer.database.BaseDao;
import cn.imnaer.database.define.DBConstant;
import cn.imnaer.service.persistence.model.InviteCode;
import cn.imnaer.service.persistence.model.consts.INVITECODE;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;

import java.util.List;

/**
 * 邀请码DB工具类
 * Created by Administrator on 2015/4/20.
 */
public class UserInviteDaoImpl extends BaseDao<InviteCode> {
	public  static   UserInviteDaoImpl  instance=new  UserInviteDaoImpl();
    private UserInviteDaoImpl() {
     
    }
    public static   UserInviteDaoImpl   getInstance(){
    	return  instance;
    }
    public void create(InviteCode target) {
        this.insert(target,true);
    }

    /**
     * 根据邀请码获得对象
     *
     * @param code
     * @return
     */
    public InviteCode getByCode(String code) {

        BSONObject matcher = new BasicBSONObject();
        matcher.put(INVITECODE.code, code);
        matcher.put(INVITECODE.isUse, false);
       return  this.findOne(matcher, null);
   

    }


    public void updateObject(InviteCode target) {
        BasicBSONObject matcher = new BasicBSONObject();
        matcher.put(INVITECODE.inviteId, target.getInviteId());
        this.update(matcher, target);
    }

	@Override
	protected String getDbSpaceName() {
		// TODO Auto-generated method stub
		return DBConstant.SPACE.USER_INFO_SPACE;
	}

	@Override
	protected String getDbCollectionName() {
		// TODO Auto-generated method stub
		return DBConstant.COLLECTION.INVITE_CODE;
	}

	@Override
	protected String getPrimaryKey() {
		// TODO Auto-generated method stub
		return INVITECODE.inviteId;
	}

}
